<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>创建缺陷</title>
    <link href="../css/common.css" type="text/css" rel="stylesheet"/>
</head>
<body>


<!--header-->
<header id="header" class="header">
    <div class="header-info left"><i></i><a href="pm-bug-list.html">缺陷列表</a> > 提交缺陷</div>
    <div class="right-user right">
         <div class="clear t" >             <div id="headusername" class="role"></div>             <div class="icon"></div>         </div>
        <div class="head-down">
            <ul><li><a href="edit-pwd.html">修改密码</a></li><li><a onclick="loginOut()">退出系统</a></li></ul></div><div>
    </div>
    </div>
</header>
<!--menu-->
<aside id="aside" class="aside">
    <div class="logo">运营平台</div>
    <ul class="menu" id="asidemenu">
    </ul>
</aside>

<!--content-->
<div class="content">
    <div class="page-inner">
        <div class="page-content">
            <div class="table-head"><i></i>提交缺陷</div>
            <div class="table-cont">
                <table class="content-table">

                    <tr>
                        <td><span class="red-start">*</span>缺陷主题：</td>
                        <td colspan="3"><input type="text" style="width: 92%" id="name"/></td>
                    </tr>
                    <tr>
                        <td>需求来源：</td>
                        <td>
                            <div class="search-box clear" style="display: block" id="searchBox">

                                <input class="left" placeholder="输入至少两个字" />
                                <a class="left edit-source-btn" id="goSearchBtn">搜索</a>
                                <select class="left" id="keyMatchSelect" onchange="_API.getComeSource('needSide',false,true,$(this).val())"><option>请输入关键词</option></select>
                            </div>
                        </td>
                        <td><span class="red-start">*</span>紧急程度：</td>
                        <td><select id="level"></select></td>
                    </tr>
                    <tr>
                        <td><span class="red-start">*</span>产品：</td>
                        <td><select id="product" onchange="_API.getFunctionList('functionList',false,false,'product')"></select></td>
                        <td><span class="red-start">*</span>功能模块：</td>
                        <td><select id="functionList"></select><span class="red-start" style="color: #4cae4c">先选择产品</span></td>
                    </tr>
                    <tr>
                        <td><span class="red-start">*</span>使用平台：</td>
                        <td><select id="platform"></select></td>
                        <td><span class="red-start">*</span>缺陷类型：</td>
                        <td><select id="issueType"></select></td>
                    </tr>
                    <tr>
                        <td>使用网络：</td>
                        <td><select id="networkType"></select></td>
                        <td>浏览器及版本：</td>
                        <td><input type="text" id="browser"/></td>
                    </tr>
                    <tr>
                        <td>手机及型号：</td>
                        <td><input type="text" id="mobileType" /></td>
                    </tr>
                    <tr class="area">
                        <td><span class="red-start">*</span>缺陷描述：</td>
                        <td colspan="3">
                            <textarea id="discribe"></textarea>
                        </td>
                    </tr>
                    <tr class="area">
                        <td>附件：</td>
                        <td colspan="3">
                            <a href="javascript:;" class="a-upload" id="fileUpload"><input id="file" value="请选择" type="file"/>点击这里上传</a>
                            <p class="format">支持的格式有：JPG，PNG，PDF，PPT，XLSX，XLS，CSV，DOCX，DOC，ZIP</p>
                            <p class="format">文件名不能包含*、#等特殊符号</p>
                            <ul class="addAttachmentList" id="addAttachmentList">
                            </ul>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="buttons">
                <a href="pm-bug-list.html" class="cancel">返回</a>
                <a onclick="commit(this)">提交</a>
            </div>
        </div>
    </div>
</div>
<script src="../js/jquery.min.js"></script>
<script src="../js/jquery.cookie.js"></script>
<script src="../js/common.js"></script>

<script type="text/javascript">
    
    _API.getProNameList('source')
        .getLevelList('level')
        .getProductList('product')
        .getPlatformList('platform')
        .getIssueType('issueType')
        .getFunctionList('functionList',false,false,false,'MDISP')
        .getNetWorkList('networkType');

    //修改需求来源
    var searchBox = $('#searchBox');
    var existSourceBox = $('#existSourceBox');
    var goSearchBtn = $('#goSearchBtn');
    var keyMatchSelect = $('#keyMatchSelect');
    goSearchBtn.on('click',function () {
        var _val = $(this).siblings('input').val();
        if(_val.length < 2) return;
        _API.checkProNameList('keyMatchSelect',0,true,_val)
    })

    // 上传文件
    var attachment = new attachment();
    attachment.init({
        fileUpload:$('#fileUpload'),
        addAttachmentList:$('#addAttachmentList')
    });


    var needName = $('#name');
        discribe = $('#discribe');
    needName.focus(function(){
        needName.removeClass('error-i');
    })
    discribe.focus(function(){
        discribe.removeClass('error-i');
    })


    var isClick = false;
    function commit(that) {
        if(needName.val() == ''){
            needName.addClass('error-i');
            return
        } 
        if( discribe.val() == ''){
            discribe.addClass('error-i');
            return;
        }

        var attachment = [];
        var li = $('#addAttachmentList').find('li');
        if(li.length >= 1){
            li.each(function(){
                attachment.push( $(this).attr('rel') );
            })
        }

        var url  = _ip+'/issue/addIssue';
        var data = {
            "name":$('#name').val(),
            "type":$('#issueType').val(),
            "networkType":$('#networkType').val(),
            "mobileType":$('#mobileType').val() || null,
            "product":$('#product').val(),
            "plat":$('#platform').val(),
            "feature":$('#functionList').val(),
            "browser":$('#browser').val() || null,
            "discribe":$('#discribe').val(),
            "remark":$('#remark').val(),
//            "creater":$.cookie('username'),
            "attachment":attachment.join(','),
            "status":"新建",
            "level":$('#level').val(),
            "projectId":$('#keyMatchSelect').val() == "请输入关键词"?null:$('#keyMatchSelect').val()
        }
        if(isClick) return;
        $(that).addClass('sending');
        isClick = true;
        $.ajax({
            url:url,
            type : "POST",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            dataType: 'json',
            contentType:'application/json',
            data:JSON.stringify(data),
            success: function(data) {
                if(data.message === 'LOGIN') {
                    window.location.href = 'user-login.html';
                    return false;
                }
                if(data.success){

                    location.href = 'pm-bug-list.html';
                }else{
                    $(that).removeClass('sending');
                    isClick = false;
                    alert('添加失败, 请稍后重试！');
                }
            }
        })
   }


</script>
</body>
</html>